package com.tr.rentcar.controller.loginandregister;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tr.rentcar.model.dao.UserDao;

/**
 * Servlet implementation class Name 判断姓名是否重名，是否不符合规范
 */
@WebServlet("/name")
public class NameController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserDao udao = new UserDao();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		String tel = request.getParameter("tel");
		String zc = request.getParameter("zc");
		String dl = request.getParameter("dl");
		Pattern reg = Pattern.compile("^1[3578]\\d{9}$");
		try {
			if (!reg.matcher(tel).find()) {
				out.print("您输入的电话号码格式不对!");
				return;
			} else if (udao.findByTel(tel) == null && "dl".equals(dl)) {
				out.print("您输入的电话不存在！");
				return;
			}else if (udao.findByTel(tel) != null && "zc".equals(zc)) {
				out.print("您输入的电话已存在,请重新输入！");
				return;
			}else {

				out.print("success");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
